using System;
using System.Globalization;
using System.Reflection;
using ns20;

namespace Newtonsoft.Json.Serialization
{
	public class DynamicValueProvider : IValueProvider
	{
		private readonly MemberInfo memberInfo_0;

		private Func<object, object> func_0;

		private Action<object, object> action_0;

		public DynamicValueProvider(MemberInfo memberInfo)
		{
			Class204.smethod_2(memberInfo, "memberInfo");
			memberInfo_0 = memberInfo;
		}

		public void SetValue(object target, object value)
		{
			try
			{
				if (action_0 == null)
				{
					action_0 = Class168.class168_0.method_1<object>(memberInfo_0);
				}
				action_0(target, value);
			}
			catch (Exception innerException)
			{
				throw new JsonSerializationException("Error setting value to '{0}' on '{1}'.".smethod_1(CultureInfo.InvariantCulture, memberInfo_0.Name, target.GetType()), innerException);
			}
		}

		public object GetValue(object target)
		{
			try
			{
				if (func_0 == null)
				{
					func_0 = Class168.class168_0.method_0<object>(memberInfo_0);
				}
				return func_0(target);
			}
			catch (Exception innerException)
			{
				throw new JsonSerializationException("Error getting value from '{0}' on '{1}'.".smethod_1(CultureInfo.InvariantCulture, memberInfo_0.Name, target.GetType()), innerException);
			}
		}
	}
}
